<template>
	<view>
		<view style="height: 1em;"></view>
		<view>
			<button type="button" @click="yearGetter">{{ yearcaption }}</button>
		</view>
		<view class="hjpanel">
			<view class="hj" v-for="(jq, index) in jieqiList" :key="index" @click="jieqiSelected(index)">
				<view style="text-align: right;width: 28%;">{{ jq[0] }}</view>
				&nbsp;:&nbsp;
				<view style="text-align: left;">{{ jq[1] }}</view>
			</view>
		</view>
		<view style="height: 1em;"></view>
		<view style="white-space: pre-wrap; padding: 1em;font-size: 22px;">
			{{ jieqiScription }}
		</view>
	</view>
</template>

<script lang="ts">
	import { POOL_SUB_ID_SHIT } from 'XrFrame/kanata/lib/kanata';
	import { ChinaDate } from '../../common/ChinaDate';
	import { dateUtil } from '../../common/dateUtil';
	import { GanZhi } from '../../common/ganzhi';
	import { SiZhu } from '../../common/sizhu';
	import { JieQi } from '../../common/jieqi';

	export default {
		data() {
			return {
				currentYear: undefined as number | undefined,
				yearcaption: "选择年份",
				jieqiList: [] as [string, string][],
				jieqiScription: "",
				currentJieqi: undefined as number | undefined,
			}
		},
		methods: {
			yearGetter() {
				uni.navigateTo({
					url: "/pages/dategetter/yeargetter",
					events: {
						selected: (year : number) => {
							console.log("jieqi.vue->yearget->selected: " + (year ? year.toString() : ""))
							this.currentYear = year;
							this.yearSelected2(year);
						}
					},
					success: (res) => {
						// 通过eventChannel向被打开页面传送数据
						res.eventChannel.emit('init', this.currentYear)
					}
				})
			},
			yearSelected2(year : number) {
				let huajia = GanZhi.getHuaJiaIndexByYear(year);
				let title = year.toString() + GanZhi.getGanZhiTextByHuajia(huajia) + "年（";
				let nowYear = (new Date()).getFullYear();
				if (year <= nowYear) title += (nowYear - year + 1).toString() + "虚岁";
				title += "属" + dateUtil.getYearProperty(year);
				title += GanZhi.getNaYinText(huajia) + "）";
				this.yearcaption = title;
				let jieqi : [string, string][] = [];
				for (let xx = 0; xx < 24; xx++) {
					jieqi.push([JieQi.getJieQiName(xx), dateUtil.FormatDate(JieQi.getJieQi(year, xx), "MM-dd hh:mm")]);
				}
				this.currentYear = year;
				this.jieqiList = jieqi;
				if (this.currentJieqi) this.jieqiSelected(this.currentJieqi);
			},
			jieqiSelected(jieqi : number) {
				if (!this.currentYear) { this.jieqiScription = ""; return; }
				let text = JieQi.getJieQiName(jieqi) + '\r\n\r\n';
				let date = JieQi.getJieQi(this.currentYear, jieqi);
				text += "公历：" + dateUtil.FormatDate(date, "yyyy年MM月dd日 hh:mm") + "\r\n";
				let china = ChinaDate.getChinaDate(date)
				china.Hour = date.getHours() >> 1;
				text += "农历：" + china.getText() + "\r\n";
				let sizhu = SiZhu.getSiZhu(date, true, true);
				text += sizhu.getText();
				this.jieqiScription = text;
			}
		},
	}
</script>

<style>
	.hjpanel {
		display: flex;
		flex-direction: row;
		border-top: solid #76b043 1px;
		border-left: solid #76b043 1px;
		flex-wrap: wrap;
		margin-top: 1em;
	}

	.hj {
		display: flex;
		flex-shrink: 1;
		flex-grow: 1;
		padding-top: 5px;
		padding-bottom: 5px;
		border-right: solid #76b043 1px;
		border-bottom: solid #76b043 1px;
		width: 40%;
		text-align: center;
		font-size: 19px;
		word-wrap: break-word;
	}
</style>